PowerShell Script for Removing All Assemblies in a Folder

Comments 0

Share to social media

You may have seen my blog post on how to add all of the assemblies from a folder into the GAC.  Here is a quick PowerShell script to do the reverse – it looks through a list of assemblies in a folder and removes them from the GAC:

$gacUtilLocation = “C:Program Files (x86)Microsoft SDKsWindowsv7.0ABinx64gacutil.exe”;

get-childitem * -include *.dll,*.exe | foreach-object {
    Write-Host “Removing” $asm.FullName
    $asm = [System.Reflection.Assembly]::LoadFile($_)
    $command = “&`”{0}`”/nologo /u `”{1}`”” -f $gacUtilLocation,$asm.FullName   
    invoke-expression $command
}

I find this helpful in SharePoint to make sure the GAC is clear of any of my development assemblies before doing a proper deployment from a WSP. 

Load comments

About the author

Damon Armstrong

See Profile

Damon Armstrong is a consultant with SystemwarePS in Dallas, Texas. He is also a blogger and author of Pro ASP.NET 2.0 Website Programming and SharePoint 2013 Essentials for Developers. He specializes in the Microsoft stack with a focus on web technologies like MVC, ASP.NET, JavaScript, and SharePoint. When not staying up all night coding, he can be found watching a bunch of kids, studying Biblical topics, playing golf, or recovering from staying up all night coding.